package com.wlyuan.index.domain.source.valueobj;

import com.wlyuan.core.marker.INamed;
import com.wlyuan.core.marker.NamedMap;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;

/**
 * @author yuanjie
 * <p>
 * /**
 * @author yuanjie
 * DRAFT(0, "草稿"),
 * WAIT_ME_AUDIT(10, "待本方审核"),
 * WAIT_OTHER_AUDIT(20, "待审核"),
 * ME_REFUSE(30, "本方拒绝"),
 * OTHER_REFUSE(40, "被拒绝"),
 * RECONCILIATION(50, "已对账"),
 * BILL_DONE(60, "已结账"),
 * CLOSE(-1, "已关闭"),
 * DELETE(-2, "已删除");
 */
@AllArgsConstructor
@Getter
public enum BillStatus implements INamed<Integer> {
    DISCARDED(-2, "已作废", true), // 对账单作废后能报价
    CLOSED(-1, "已关闭", true), // 对账单关闭后能报价
    DRAFT(0, "草稿", false), // 存在对账单草稿不能报价
    PENDING(10, "待处理", false), // 存在待处理的对账单不能报价
    AUDITING(20, "待审核", true), // 发送对账单后待审核能报价，报价系统提示已加入对账单
    REFUSED(30, "已拒绝", true), // 拒绝对方对账单后能报价
    REJECTED(40, "已驳回", false), // 被对方驳回对账单后不能报价
    COMPLETED(50, "已对账", false), // 对账单已对账不能报价
    WAITING(80, "待对账", true); // 生成的状态，表示处于待对账状态

    private final Integer value;
    private final String name;
    private final boolean canBill;


    private static final int PRIORITY_MAX = 100;

    public int getPriority() {
        // 草稿状态对账单优先级最高
        if (DRAFT == this) {
            return PRIORITY_MAX;
        }
        return this.getValue();
    }

    private static final Map<Integer, BillStatus> STATUSES = new NamedMap<>(BillStatus.class);

    public static BillStatus valueOf(Integer value) {
        return STATUSES.get(value);
    }

    public boolean isCanQuote() {
        return this.isCanBill();
    }
}
